<?php
/**
 * Created by PhpStorm.
 * User: sunqiang
 * Date: 2018/8/30
 * Time: 上午9:50
 */

namespace common\service;

use Yii;

class WarehouseService
{

    /**
     * 获取所有可用仓库
     * @return array
     * @throws \yii\db\Exception
     */
    public static function findAll()
    {
        $sql = 'SELECT * FROM `j_warehouse` WHERE `useFlg` = 1';
        $cmd = Yii::$app->db->createCommand($sql);
        return $cmd->queryAll();
    }


    /**
     * 根据ID获取可用仓库
     */
    public static function findWarehouseByIds($ids)
    {
        if (!is_array($ids)) {
            $ids = array($ids);
        }


        $str_ids = implode(',', $ids);

        $sql = 'SELECT * FROM `j_warehouse` WHERE `useFlg` = 1 AND FIND_IN_SET(id,:ids)';
        $cmd = Yii::$app->db->createCommand($sql);
        $cmd->bindParam(':ids', $str_ids, \PDO::PARAM_STR);

        return $cmd->queryAll();

    }
}